#!/bin/sh

mk_ajajform() {
	rm -f ajajform
	ln -s /home/projects/ajajform/ajajform ajajform
}

mk_reset() {
	wget -O reset.css http://www.100baza.ru/m/css/reset.css
}

mk_jqueryui_touch() {
	wget -O jquery.ui.touch.js http://jquery-ui-for-ipad-and-iphone.googlecode.com/files/jquery.ui.touch.js
}
mk_swfupload() {
	rm -rf jquery.swfupload
	# jquery.swfupload
	wget -nv --no-check-certificate -O jquery.swfupload.zip https://github.com/ifunk/swfupload-jquery-plugin/zipball/master
	unzip jquery.swfupload.zip >/dev/null 2>/dev/null
	mkdir jquery.swfupload
	mv ifunk-swfupload-jquery-plugin-*/src/jquery.swfupload.js jquery.swfupload/
	mv ifunk-swfupload-jquery-plugin-*/vendor/swfupload jquery.swfupload/
	rm -rf ifunk-swfupload-jquery-plugin-*
	rm -f jquery.swfupload.zip
}

mk_jqueryui() {
	# jqueryui
	rm -rf jqueryui
	mkdir jqueryui
	mkdir jqueryui/css
	for A in '1' '2' '3' '4' '5'; do
		rm -rf /tmp/jqueryui
		unzip /tmp/jquery-ui-$A.zip -d /tmp/jqueryui  >/dev/null 2>/dev/null
#		if [ "$A" == "1" ]; then
		cp /tmp/jqueryui/js/jquery-ui-1.8.13.custom.min.js jqueryui/jquery-ui.js
#		fi
		B=`ls /tmp/jqueryui/css`
		mv /tmp/jqueryui/css/$B/ jqueryui/css/
		mv jqueryui/css/$B/jquery-ui-1.8.13.custom.css jqueryui/css/$B/jquery-ui.css
	done
}

mk_jquery_galleriffic() {
	rm -rf galleriffic
	wget -nv -O galleriffic.zip http://www.twospy.com/galleriffic/galleriffic-2.0.zip
	unzip galleriffic.zip >/dev/null 2>/dev/null
	mv galleriffic-2.0 jquery.galleriffic
	rm -f galleriffic.zip
}

mk_jquery_history() {
	rm -f jquery.history.js
	wget -nv --no-check-certificate -O jquery.history.js https://github.com/tkyk/jquery-history-plugin/raw/master/jquery.history.js
}

mk_jqueryui_orig() {
	# jqueryui
	rm -rf jqueryui
	wget -nv -O jquery-ui-1.8.13.custom.zip http://jqueryui.com/download/jquery-ui-1.8.9.custom.zip
	unzip jquery-ui-1.8.13.custom.zip -d jqueryui >/dev/null 2>/dev/null
	mv jqueryui/js/jquery-ui-1.8.13.custom.min.js jqueryui/jquery-ui.js
	rm -f jquery-ui-1.8.13.custom.zip

	mkdir jqueryui/css
	for A in 'smoothness' 'ui-lightness'; do
		if [ "$A" != "smoothness" ]; then
			mkdir jqueryui/css/$A
			mkdir jqueryui/css/$A/images
			cp jqueryui/css/smoothness/images/* jqueryui/css/$A/images/
		fi
		wget -nv -O jqueryui/css/$A/jquery-ui.css http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/themes/$A/jquery-ui.css
	done
}

mk_tiny_mce() {
	rm -rf tiny_mce
	# tiny_mce
	wget -nv -O tinymce_3_3_9_3_jquery.zip --no-check-certificate "http://tinymce.moxiecode.com/track.php?url=http%3A%2F%2Fgithub.com%2Fdownloads%2Ftinymce%2Ftinymce%2Ftinymce_3_3_9_3_jquery.zip"
	unzip tinymce_3_3_9_3_jquery.zip >/dev/null 2>/dev/null
	rm -f tinymce_3_3_9_3_jquery.zip
	mv tinymce/jscripts/tiny_mce tiny_mce
	rm -rf tinymce
}

mk_jquery() {
	rm -f jquery.js
	wget -nv -O jquery.js http://code.jquery.com/jquery-1.7.2.min.js
}

mk_raphael() {
	rm -f raphael-min.js
	wget -nv --no-check-certificate -O raphael-min.js http://github.com/DmitryBaranovskiy/raphael/raw/master/raphael-min.js
}

mk_graphael() {
	rm -rf graphael
	mkdir graphael
	wget -nv --no-check-certificate -O graphael/g.raphael-min.js http://github.com/DmitryBaranovskiy/g.raphael/blob/master/g.raphael-min.js?raw=true
	wget -nv --no-check-certificate -O graphael/g.pie-min.js http://github.com/DmitryBaranovskiy/g.raphael/blob/master/g.pie-min.js?raw=true
	wget -nv --no-check-certificate -O graphael/g.bar-min.js http://github.com/DmitryBaranovskiy/g.raphael/blob/master/g.bar-min.js?raw=true
	wget -nv --no-check-certificate -O graphael/g.dot-min.js http://github.com/DmitryBaranovskiy/g.raphael/blob/master/g.dot-min.js?raw=true
	wget -nv --no-check-certificate -O graphael/g.line-min.js http://github.com/DmitryBaranovskiy/g.raphael/blob/master/g.line-min.js?raw=true
}


mk_swfobject() {
	rm -f swfobject.js
	wget -nv --no-check-certificate -O swfobject_2_2.zip http://swfobject.googlecode.com/files/swfobject_2_2.zip
	unzip swfobject_2_2.zip swfobject/swfobject.js
	mv swfobject/swfobject.js swfobject.js
	rm -rf swfobject
	rm -f swfobject_2_2.zip
}

mk_jquery_json() {
	rm -f jquery.json.js
	wget -nv -O jquery.json.js http://jquery-json.googlecode.com/files/jquery.json-2.2.min.js
}

mk_jquery_lightbox() {
	rm -rf jquery_lightbox
	wget -nv -O jquery_lightbox.zip http://leandrovieira.com/download/7/
	mkdir jquery_lightbox
	mkdir jquery_lightbox/js
	unzip jquery_lightbox.zip "css/*" -d jquery_lightbox >/dev/null 2>/dev/null
	unzip jquery_lightbox.zip "images/*" -d jquery_lightbox >/dev/null 2>/dev/null
	unzip jquery_lightbox.zip js/jquery.lightbox-0.5.min.js -d jquery_lightbox >/dev/null 2>/dev/null
	mv jquery_lightbox/js/jquery.lightbox-0.5.min.js jquery_lightbox/js/jquery.lightbox.min.js
	mv jquery_lightbox/css/jquery.lightbox-0.5.css jquery_lightbox/css/jquery.lightbox.css
	rm -f jquery_lightbox.zip
}

mk_editarea() {
	rm -rf editarea_0_8_2
	wget -nv -O "editarea_0_8_2.zip" "http://downloads.sourceforge.net/project/editarea/EditArea/EditArea%200.8.2/editarea_0_8_2.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Feditarea%2Ffiles%2F&ts=1304323901&use_mirror=citylan"
	unzip editarea_0_8_2.zip
	rm -f editarea_0_8_2.zip
}

case "$1" in
	all)
		mk_ajajform
		mk_swfupload
		mk_jqueryui
		mk_tiny_mce
		mk_jquery
		mk_raphael
		mk_graphael
		mk_swfobject
		mk_jquery_lightbox
		mk_jquery_galleriffic
		MK_JQUery_history
		mk_jquery_json
		mk_jqueryui_touch
		mk_editarea
		mk_reset
		;;
	editarea)
		mk_editarea
		;;
	reset)
		mk_reset
		;;
	jquery_galleriffic)
		mk_jquery_galleriffic
		;;
	jquery_history)
		mk_jquery_history
		;;
	ajajform)
		mk_ajajform
		;;
	swfupload)
		mk_swfupload
		;;
	jqueryui)
		mk_jqueryui
		;;
	tiny_mce)
		mk_tiny_mce
		;;
	jquery)
		mk_jquery
		;;
	raphael)
		mk_raphael
		;;
	graphael)
		mk_graphael
		;;
	swfobject)
		mk_swfobject
		;;
	jquery_lightbox)
		mk_jquery_lightbox
		;;
	jquery_json)
		mk_jquery_json
		;;
	jqueryui_touch)
		mk_jqueryui_touch
		;;
	*)
		echo "$0 (all|ajajform|swfupload|jqueryui|jqueryu|tiny_mce|raphael|swfobject|jquery_lightbox|jquery_galleriffic|jquery_history|jquery_json|editarea)"
		;;
esac


